package BigDecimal类编程题;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;

public class Student {
    private String name;
    private String gender;
    private Integer age;
    private BigDecimal grade;

    public Student(String name, String gender, Integer age, double grade) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.grade = BigDecimal.valueOf(grade);
    }
    public BigDecimal getGrade(){
        return grade;
    }
}

class TestGrades{
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("张三","男",20,79.5));
        students.add(new Student("李四","女",21,80.2));
        students.add(new Student("王五","男",22,77.9));
        students.add(new Student("周六","男",20,55.8));
        students.add(new Student("赵七","男",21,99.9));
        BigDecimal sum = new BigDecimal("0.00");
        for (int i = 0; i < students.size(); i++) {
            sum=sum.add(students.get(i).getGrade());
        }
        BigDecimal average = sum.divide(BigDecimal.valueOf(students.size()),2, RoundingMode.HALF_UP);
        System.out.println(average);
    }
}
